<template>
  <div class="app-container">    
    <div class="filter-container">
      <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="发送时间" prop="sendTime">
          <el-date-picker
            v-model="filterForm.sendTime"
            value-format="yyyy-MM-dd"
            type="daterange"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="filterForm.readStatus"  @input="handleFilter">
            <el-radio-button label="0">全部</el-radio-button>
            <el-radio-button label="2">已读</el-radio-button>
            <el-radio-button label="1">未读</el-radio-button>
          </el-radio-group>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      stripe
      border
      fit
      highlight-current-row
      style="width: 100%;"
      @sort-change="sortChange"
    >
      <el-table-column label="主题" align="left" width="200">
        <template slot-scope="{row}">
          <span>{{ row.message.subject }}</span>
        </template>
      </el-table-column>
      <el-table-column label="内容" align="left">
        <template slot-scope="{row}">
          <span>{{ row.message.content }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="left" width="100px">
        <template slot-scope="{row}">
          <el-tag v-if="row.status == 2">已读</el-tag>
          <el-tag v-else>未读</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="发送时间" width="180px">
        <template slot-scope="{row}">
          <span>{{ row.createdAt }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getList" />
  </div>
</template>

<script>
//import { getFaultinessList,  removeFaultinessByID, changeFaultinessStatusByID } from '@/api/development/faultiness'
import waves from '@/directive/waves' // waves directive
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getMessgeInbox} from '@/api/messenger/message'

export default {
  name: 'financeDashboard',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      
      socket:"",
      tableKey: 0,
      list: null,
      windowHeight:"800",
      total: 0,
      listLoading: false,
      connected:"loading",
      filterForm: {
        start: 1,
        perpage: 10,
        readStatus:'0',
      }
    }
  },
  created() {
    this.getList()
  },
  destroyed(){
  },
  methods: {
    handleDepositSubmit:function(){
      this.send({
        "conversationType":"finance.deposit.save",
        "message":this.depositForm,
        "target":{"id":"3"}
      })
    },
    getList:function(){
      let _this = this;
      console.log(_this.filterForm)
      getMessgeInbox(_this.filterForm).then((response) => {
        console.log(response)
          if (response.code === 200) {
            this.list = response.data.list
            this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleFilter() {
      this.filterForm.page = 1
      this.getList()
    },
    sortChange(data) {
      const { prop, order } = data
      if (prop === 'id') {
        this.sortByID(order)
      }
    },
    sortByID(order) {
      if (order === 'ascending') {
        this.filterForm.sort = '+id'
      } else {
        this.filterForm.sort = '-id'
      }
      this.handleFilter()
    }
  }
}
</script>
<style>

</style>